#include "HitState.h"
#include "Array.h"

namespace baker
{
    //--------------------------------------------------------------------------
    class HitStateImpl
    {
    public:
        HitStateImpl() {}
        ~HitStateImpl() {}

        guint getHitCount() const
        {
            return mHits.length();
        }

        static bool less( const HitInfo & lhs
                        , const HitInfo & rhs
                        )
        {
            return lhs.dist < rhs.dist;
        }

        guint getClosestHitIndex() const
        {
            return indexOfMin( mHits, &HitStateImpl::less );
        }

        const HitInfo & getHitInfo( guint hitIndex ) const
        {
            g_assert( hitIndex < mHits.length() );

            return mHits.at( hitIndex );
        }

        HitInfo &  appendHitInfo()
        {
            HitInfo info;
            mHits.append( info );

            return mHits.at( mHits.length() - 1 );
        }

    private:
        Array<HitInfo> mHits;
    };

    //--------------------------------------------------------------------------
    HitState::HitState()
        : mImpl( new HitStateImpl )
    {
    }

    //--------------------------------------------------------------------------
    HitState::~HitState()
    {
        safeDelete( mImpl );
    }

    //--------------------------------------------------------------------------
    guint HitState::getHitCount() const
    {
        return mImpl->getHitCount();
    }

    //--------------------------------------------------------------------------
    guint HitState::getClosestHitIndex() const
    {
        return mImpl->getClosestHitIndex();
    }

    //--------------------------------------------------------------------------
    const HitInfo & HitState::getHitInfo( guint hitIndex ) const
    {
        return mImpl->getHitInfo( hitIndex );
    }

    //--------------------------------------------------------------------------
    HitInfo & HitState::appendHitInfo()
    {
        return mImpl->appendHitInfo();
    }

    //--------------------------------------------------------------------------
    //--------------------------------------------------------------------------
    //--------------------------------------------------------------------------
}
